home *** CD-ROM | disk | FTP | other *** search
/ Apple WWDC 1996 / WWDC96_1996 (CD).toast / Technology Materials / MacApp Release 10 / MacApp Release 10 - HD Ready / Libraries / Views / Includes / UGridView.h < prev    next >
Encoding:
Text File  |  1996-04-03  |  38.9 KB  |  1,140 lines  |  [TEXT/MPS ]

  1. // UGridView.h
  2. // Copyright © 1984-96 by Apple Computer, Inc. All rights reserved.
  3.  
  4.  
  5. #ifndef __UGRIDVIEW__
  6. #define __UGRIDVIEW__
  7.  
  8. // MacApp
  9.  
  10. #ifndef __UGEOMETRY__
  11. #include "UGeometry.h"
  12. #endif
  13.  
  14. #ifndef __UITERATOR__
  15. #include "UIterator.h"
  16. #endif
  17.  
  18. #ifndef __UTRACKER__
  19. #include "UTracker.h"
  20. #endif
  21.  
  22. #ifndef __UVIEW__
  23. #include "UView.h"
  24. #endif
  25.  
  26. // Toolbox
  27.  
  28.  
  29. //----------------------------------------------------------------------------------------
  30. // Forward and external class declarations. 
  31. //----------------------------------------------------------------------------------------
  32.  
  33. class TDocument;
  34. class TDragItem;
  35. class TToolboxEvent;
  36.  
  37.  
  38. //----------------------------------------------------------------------------------------
  39. // Boolean for Adornment
  40. //----------------------------------------------------------------------------------------
  41.  
  42. const Boolean kAdorn = TRUE;
  43. const Boolean kDontAdorn = FALSE;
  44.  
  45.  
  46. //----------------------------------------------------------------------------------------
  47. // Booleans for SetSelection
  48. //----------------------------------------------------------------------------------------
  49.  
  50. const Boolean kExtend = TRUE;
  51. const Boolean kDontExtend = FALSE;
  52.  
  53. const Boolean kHighlight = TRUE;
  54. const Boolean kDontHighlight = FALSE;
  55.  
  56. const Boolean kSelect = TRUE;
  57. const Boolean kDeSelect = FALSE;
  58.  
  59.  
  60. //----------------------------------------------------------------------------------------
  61. // Typedefs
  62. //----------------------------------------------------------------------------------------
  63.  
  64. typedef CPoint GridCell;
  65.     // A cell is a QuickDraw point
  66.     
  67. enum GridViewPart { badChoice, inCell, inRow, inColumn, inVertex };
  68.  
  69.  
  70. //----------------------------------------------------------------------------------------
  71. // RunArrayChunk
  72. //----------------------------------------------------------------------------------------
  73.  
  74. typedef struct RunArrayChunk
  75. {
  76.     short count;                                // Number of consecutive items with this
  77.                                                 // value
  78.  
  79.     short value;                                // The value represented by this chunk
  80. } *ChunkArrayPtr;
  81.  
  82.  
  83. //----------------------------------------------------------------------------------------
  84. // TRunArray: The run array class is used to maintain the column widths and row heights.
  85. // Entries in the array are values for a given item, where the items are indexed from one.
  86. // fNoOfItems indicates the number of items (and values) in the array. The values are
  87. // maintained in "chunks" which lump together consecutive items with the same value. A
  88. // variable length array, fChunks, is used to store the chunks. It is indexed from zero.
  89. //----------------------------------------------------------------------------------------
  90.  
  91. class TRunArray : public TObject
  92. {
  93.     MA_DECLARE_CLASS;
  94.     
  95. public:
  96.     TRunArray();
  97.         // Constructor
  98.         
  99.     void IRunArray();
  100.         // Initializes a run array to have zero items.
  101.  
  102.     virtual ~TRunArray();
  103.         // Frees the fChunks field which is a handle to the chunks, before calling
  104.         // Inherited::Free.
  105.  
  106.     void InsertItems(short firstItem,
  107.                                     short noOfItems,
  108.                                     short value);
  109.         // Inserts the indicated items into the run array, all of which have the given
  110.         // value.
  111.  
  112.     void DeleteItems(short firstItem,
  113.                                     short noOfItems);
  114.         // Deletes the indicated items from the run array.
  115.  
  116.     Boolean FindChunk(short item,
  117.                                      short& chunk,
  118.                                      short& indexInChunk,
  119.                                      long& theTotal);
  120.         // Returns information about a given item in the run array. chunk indicates the
  121.         // chunk in which the item is located, where zero is the first chunk in the run
  122.         // array. indexInChunk is the location of the item withinin the chunk. Note that
  123.         // the chunk indexes are one-based--the first item in the chunk is index 1.
  124.         // theTotal is the sum of values up to, but not including, the chunk in which the
  125.         // given item is located. FindChunk returns false if the given item is outside the
  126.         // range of items in the run-array (i.e. item < 1 or item > fNoOfItems), or the
  127.         // given item is not represented in a chunk (i.e. a bug).
  128.         //
  129.           // Example: Item    Value    Chunk    indexInChunk    theTotal
  130.          // 10501000
  131.          // 20502000
  132.          // 32011010
  133.          // 43521030
  134.          // 53522030
  135.         // 61031100
  136.  
  137.     short FindItem(long theTotal);
  138.         // Returns the item number for which the sum of the values exceeds theTotal, or
  139.         // zero if theTotal is outside the sum of values represented by the run array.
  140.  
  141.     short GetValue(short item);
  142.         // Returns the value for the given item.
  143.  
  144.     long SumValues(short firstItem, short noOfItems);
  145.         // Returns the sum of the values over the given items.
  146.  
  147.     inline RunArrayChunk& ChunkAt(ArrayIndex chunkIndex)
  148.     { return *(RunArrayChunk*)(*fChunks)[chunkIndex]; }
  149.         // returns a reference to the indexed chunk
  150.  
  151.     inline long GetTotal()
  152.     { return fTotal; }
  153.  
  154.     inline void SetTotal(long newTotal)
  155.     { fTotal = newTotal; }
  156.  
  157.     inline short GetNoOfChunks()
  158.     { return fNoOfChunks; }
  159.  
  160.     //----------------------------------------------------------------------------------------
  161.     // data members
  162.     //----------------------------------------------------------------------------------------
  163. public:
  164.     long fTotal;                                // The sum of the values in the run array
  165.  
  166.     short fNoOfChunks;                            // Number of chunks in the run array
  167.  
  168. protected:
  169.     TDynamicArray* fChunks;                        // The chunks themselves.
  170.  
  171.     long fLastTotal;                            // cache the last total calculated
  172.  
  173.     short fLastItem;                            // cache the last item found
  174.  
  175.     short fLastChunk;                            // cache the last chunk found
  176.  
  177.     short fLastIndex;                            // cache the last index used
  178.  
  179.     short fNoOfItems;                            // Number of items (values) in this
  180.                                                 // run-array
  181. };
  182.  
  183.  
  184. //----------------------------------------------------------------------------------------
  185. // TGridView: TGridView forms the base class for a building block that allows the creation
  186. // of views that can contain and manage cells, similar to a spreadsheet.
  187. //----------------------------------------------------------------------------------------
  188.  
  189. class TGridView : public TView
  190. {
  191.     MA_DECLARE_CLASS;
  192.     
  193. public:
  194.  
  195.     TGridView();
  196.         // Constructor
  197.         
  198.     void IGridView(TDocument* itsDocument,
  199.                                   TView* itsSuperView,
  200.                                   const VPoint& itsLocation,
  201.                                   const VPoint& itsSize,
  202.                                   SizeDeterminer itsHSizeDet,
  203.                                   SizeDeterminer itsVSizeDet,
  204.                                   short numOfRows,
  205.                                   short numOfCols,
  206.                                   short rowHeight,
  207.                                   short colWidth,
  208.                                   Boolean adornRows,
  209.                                   Boolean adornCols,
  210.                                   short rowInset,
  211.                                   short colInset,
  212.                                   Boolean singleSelection);
  213.         // Initialize the gridview. If numOfRows or numOfCols is non-zero then the
  214.         // gridview is initialized to the specified size using rowHeight and colWidth if
  215.         // the sizedeterminer is sizeVariable. If either adorn is kDontAdorn, then that
  216.         // adorn will not be called.
  217.  
  218.     virtual TObject* Clone();
  219.         // calls Inherited::Clone and then clones owned objects
  220.  
  221.     virtual ~TGridView();
  222.         // Free the TGridView object
  223.  
  224.  
  225.     //------------------------------------------------------------------------------------
  226.     // Standard signature support.
  227.     //------------------------------------------------------------------------------------
  228.  
  229.     virtual IDType GetStandardSignature();    // override 
  230.         // Returns this class's standard signature.
  231.  
  232.     //------------------------------------------------------------------------------------
  233.     // Stream I/O protocol support.
  234.     //------------------------------------------------------------------------------------
  235.  
  236.     virtual void ReadFields(TStream* aStream);    // override 
  237.     
  238.     virtual void WriteFields(TStream* aStream);    // override 
  239.  
  240.     //------------------------------------------------------------------------------------
  241.     // Inherited Methods(OVERRIDE)
  242.     //------------------------------------------------------------------------------------
  243.  
  244.     virtual void DoMenuCommand(CommandNumber aCommandNumber); // Override
  245.         // Handles the Select All menu command
  246.  
  247.     virtual VRect CalcMinFrame();
  248.         // Sets the extent of the view.
  249.  
  250.     virtual void DoHighlightSelection(HLState fromHL, HLState toHL);
  251.         // Do highlighting
  252.  
  253.     virtual void DoMouseCommand(VPoint& theMouse,
  254.                                        TToolboxEvent* event,
  255.                                        CPoint hysteresis);
  256.         // Handle mouse commands
  257.  
  258.     virtual void Draw(const VRect& area);
  259.         // Calls DrawRangeOfCells and AdornRow/ Col as appropriate.
  260.  
  261.  
  262.     //------------------------------------------------------------------------------------
  263.     // UGridView Methods to OVERRIDE
  264.     //------------------------------------------------------------------------------------
  265.  
  266.     virtual void AdornCol(short aCol, const VRect& area);
  267.         // If fAdornCol is true, this method is called to draw the column adornments.
  268.  
  269.     virtual void AdornRow(short aRow, const VRect& area);
  270.         // If fAdornRow is true, this method is called to draw the rowadornments.
  271.  
  272.     virtual Boolean CanSelectCell(GridCell aCell);
  273.         // This method checks to see if a cell can be seleced. By default, this method
  274.         // always returns true.
  275.  
  276.     virtual void HighlightCells(RgnHandle theCells, HLState fromHL, HLState toHL);
  277.         // Highlights the cells in theCells according to the given highlight state.
  278.  
  279.     virtual void DrawRangeOfCells(GridCell startCell,
  280.                                          GridCell stopCell,
  281.                                          const VRect& aRect);
  282.         // This method calls DrawCell for each cell in need of re-drawing.
  283.  
  284.     virtual void DrawCell(GridCell aCell, const VRect& aRect);
  285.         // This method draws each individual cell.IT MUST BE OVERRIDDEN!
  286.  
  287.  
  288.     //------------------------------------------------------------------------------------
  289.     // General UGridView Methods
  290.     //------------------------------------------------------------------------------------
  291.  
  292.     VRect CellToVRect(GridCell aCell) const;
  293.     inline void CellToVRect(GridCell aCell, VRect& theVRect) const
  294.     { theVRect = CellToVRect(aCell); }
  295.         // Get the rectangle bounding a given cell. This includes the row and column
  296.         // insets.
  297.  
  298.     VRect ColToVRect(short aCol, short numOfCols) const;
  299.     inline void ColToVRect(short aCol, short numOfCols, VRect& theVRect) const
  300.     { theVRect = ColToVRect(aCol, numOfCols); }
  301.         // Get the rectangle bounding the given columns. This includes the cells in the
  302.         // row or column and the row or column insets.
  303.  
  304.     VRect RowToVRect(short aRow, short numOfRows) const;
  305.     inline void RowToVRect(short aRow, short numOfRows, VRect& theVRect) const
  306.     { theVRect = RowToVRect(aRow, numOfRows); }
  307.         // Get the rectangle bounding the given rows. This includes the cells in the row
  308.         // or column and the row or column insets.
  309.  
  310.     void CellsToPixels(RgnHandle theCells, RgnHandle thePixels);
  311.         // Returns in thePixels a region that contains all of the cells in theCells.
  312.  
  313.     virtual void DelColAt(short aCol, short numOfCols);
  314.         // Delete the specified columns, starting at 'aCol' with the number to be deleted
  315.         // 'numOfCols'.This causes a redraw of only the necessary cells.
  316.  
  317.     virtual void DelRowAt(short aRow, short numOfRows);
  318.         // Delete the specified rows, starting at 'aRow' with the number of to be deleted
  319.         // 'numOfRows'.This causes a redraw of only the necessary cells.
  320.  
  321.     virtual void DelColFirst(short numOfCols);
  322.         // Delete the specified number of columns from the beginning of the list.This
  323.         // causes a redraw of only the necessary cells.
  324.  
  325.     virtual void DelRowFirst(short numOfRows);
  326.         // Delete the specified number of rows from the beginning of the list.This causes
  327.         // a redraw of only the necessary cells.
  328.  
  329.     virtual void DelColLast(short numOfCols);
  330.         // Delete the specified number of columns from the last cell of the list.This
  331.         // causes a redraw of only the necessary cells.
  332.  
  333.     virtual void DelRowLast(short numOfRows);
  334.         // Delete the specified number of rows from the last cell of the list.This causes
  335.         // a redraw of only the necessary cells.
  336.  
  337.     virtual GridCell FirstSelectedCell();
  338.         // Returns the top left cell in the selection range, if any
  339.  
  340.     short GetColWidth(short aCol) const;
  341.         // Return the width for the specifiedcolumn.
  342.  
  343.     short GetRowHeight(short aRow) const;
  344.         // Return the height for the specified row .
  345.  
  346.     virtual GridViewPart IdentifyPoint(const VPoint& thePoint,
  347.                                               GridCell& aCell);
  348.         // Return the GridViewPart (inCell, inColumn, inRow, inVertex) in which the
  349.         // specified VPoint lies. The "vertex" is the area where a row and column meet.
  350.  
  351.     virtual void InsColBefore(short aCol, short numOfCols, short aWidth);
  352.         // Insert the specified columns before the column given.The widths of the columns
  353.         // are all set to the specified aWidth.
  354.  
  355.     virtual void InsRowBefore(short aRow, short numOfRows, short aHeight);
  356.         // Insert the specified rows before the row given.The heights of the rows are all
  357.         // set to the specified aHeight.
  358.  
  359.     virtual void InsColFirst(short numOfCols, short aWidth);
  360.         // Insert the specified number of columns at the beginning of the list.The widths
  361.         // of the columns are all set to the specified aWidth.
  362.  
  363.     virtual void InsRowFirst(short numOfRows, short aHeight);
  364.         // Insert the specified number of rows at the beginning of the list.The heights of
  365.         // the rows are all set to the specified aHeight.
  366.  
  367.     virtual void InsColLast(short numOfCols, short aWidth);
  368.         // Insert the specified number columns at the end of the list.The widths of the
  369.         // columns are all set to the specified aWidth.
  370.  
  371.     virtual void InsRowLast(short numOfRows, short aHeight);
  372.         // Insert the specified number of rows at the end of the list.The heights of the
  373.         // rows are all set to the specified aHeight.
  374.  
  375.     virtual void InvalidateCell(GridCell aCell);
  376.         // Cause a cell to be marked invalid (in need of re-drawing).
  377.  
  378.     virtual void InvalidateSelection();
  379.         // Cause the rectangle bounding the selections to be marked invalid (in need of
  380.         // re-drawing).
  381.  
  382.     virtual Boolean IsCellSelected(GridCell aCell);
  383.         // Check if the specified cell is currently selected.
  384.  
  385.     virtual Boolean IsAnyCellSelected();
  386.         // Returns true if any cell is currently selected.
  387.  
  388.     virtual GridCell LastSelectedCell();
  389.         // Returns the bottom right cell in the selection range, if any
  390.  
  391.     virtual void ScrollSelectionIntoView(Boolean redraw);    // Override
  392.         // Scroll the selection into view.
  393.  
  394.     virtual void SetColWidth(short aCol, short numOfCols, short aWidth);
  395.         // Set the width of the specified columns to that given.
  396.  
  397.     virtual void SetRowHeight(short aRow, short numOfRows, short aHeight);
  398.         // Set the height of the specified rows to that given.
  399.  
  400.     virtual void SelectCell(GridCell theCell,
  401.                                    Boolean extendSelection,
  402.                                    Boolean highlight,
  403.                                    Boolean select);
  404.         // Set the current selection to the specified cell. Sets up a region and then
  405.         // calls SetSelection.
  406.  
  407.     virtual void SetEmptySelection(Boolean highlight);
  408.         // Set the current selection to be empty or nothing. If highlight is kHighlight
  409.         // then the appropriate highlighting is performed.
  410.  
  411.     virtual void SetSelection(RgnHandle cellsToSelect,
  412.                                      Boolean extendSelection,
  413.                                      Boolean highlight,
  414.                                      Boolean select);
  415.         // Set the current selections to the specified region. If extend is kExtend then
  416.         // cellsToSelect is "added" to that already selected, if highlight is kHighlight
  417.         // then cellsToSelect is highlighted as well. IF select is kSelect then
  418.         // cellsToSelect is selected, if kDeSelect then de-selected
  419.  
  420.     virtual void SetSelectionRect(const CRect& selectionRect,
  421.                                          Boolean extendSelection,
  422.                                          Boolean highlight,
  423.                                          Boolean select);
  424.         // Set the current selections to the specified rectangle. and call SetSelection.
  425.  
  426.     virtual void SetSingleSelection(Boolean theSetting);
  427.         // If true then only one item/ cell can be selected at a time
  428.  
  429.     GridCell VPointToCell(const VPoint& aPoint) const;
  430.         // Determine the cell in which a given CPoint lies, or (0, 0) if the given CPoint
  431.         // doesn't lie within any cell.
  432.  
  433.     GridCell VPointToLastCell(const VPoint& aPoint) const;
  434.         // Returns the cell in which the given CPoint lies, or the last cell of the row/
  435.         // column if the horizontal/ vertical coordinate lies beyond the last cell of the
  436.         // row/ column.
  437.  
  438. #if qDrag
  439.     //------------------------------------------------------------------------------------
  440.     // Drag and Drop Methods
  441.     //------------------------------------------------------------------------------------
  442.  
  443.     virtual RgnHandle DoMakeDragCursorRegion(); // Override
  444.     
  445.     virtual Boolean WillDrag(const VPoint& localMouse, const RgnHandle dragCursorRegion); // Override
  446.     
  447.     virtual void DoDragEnter(); // Override
  448.     
  449.     virtual void DoDragLeave(); // Override
  450.     
  451.     virtual void DoDragWithin(const VPoint& localMouse); // Override
  452.     
  453.     virtual void DrawCellCaret(GridCell targetCell);
  454.     
  455.     
  456. #endif // qDrag
  457.     
  458. protected:
  459.     virtual void AddStrip(RgnHandle thePixels,
  460.                                   VHSelect direction,
  461.                                  short& startOfStrip,
  462.                                  short endOfStrip,
  463.                                  CRect& stripRect,
  464.                                  short row,
  465.                                  short col,
  466.                                  VRect& pixels,
  467.                                  VRect& previousPixels,
  468.                                  CRect& prevStripRect);
  469.     // Called by CellsToPixels to add a strip of cells to thePixels.
  470.  
  471.     //----------------------------------------------------------------------------------------
  472.     // data members
  473.     //----------------------------------------------------------------------------------------
  474. public:
  475.     TRunArray* fColWidths;                        // bag containing col widths
  476.  
  477.     TRunArray* fRowHeights;                        // bag containing row heights
  478.  
  479.     RgnHandle fSelections;                        // Region of currently selected cells
  480.  
  481.     RgnHandle fHLRegion;                        // Region of cells to be highlighted. This
  482.                                                 // will be different from fSelections
  483.                                                 // while selection with the mouse is
  484.                                                 // taking place.
  485.  
  486.     RgnHandle fTemporarySelections;                    // Used by SetSelectionRect
  487.  
  488.     short fNumOfRows;                            // number of rows
  489.  
  490.     short fNumOfCols;                            // number of columns
  491.  
  492.     short fRowInset;                            // Number of pixels between cell rows
  493.  
  494.     short fColInset;                            // Number of pixels between cell cols
  495.  
  496.     Boolean fAdornRows;                            // Draw adornment for rows?
  497.  
  498.     Boolean fAdornCols;                            // Draw adornment for columns?
  499.  
  500.     Boolean fSingleSelection;                    // only one cell selected at a time?
  501.  
  502. #if qDrag
  503.  
  504. protected:
  505.     
  506.     GridCell        fLastTargetCell;
  507.     
  508.     unsigned long    fLastCaretTime;
  509.     
  510.     Boolean            fCaretIsShown;
  511.  
  512. #endif //qDrag
  513. };
  514.  
  515.  
  516. //----------------------------------------------------------------------------------------
  517. // TTextGridView: A sub-class of TGridView that can handle the display of text in its
  518. // cells.
  519. //----------------------------------------------------------------------------------------
  520.  
  521. class TTextGridView : public TGridView
  522. {
  523.     MA_DECLARE_CLASS;
  524.     
  525. public:
  526.     //------------------------------------------------------------------------------------
  527.     // Initialization and Free Methods
  528.     //------------------------------------------------------------------------------------
  529.  
  530.     TTextGridView();
  531.         // Constructor
  532.     virtual ~TTextGridView();
  533.         // Destructor
  534.         
  535.     void ITextGridView(TDocument* itsDocument,
  536.                                       TView* itsSuperView,
  537.                                       const VPoint& itsLocation,
  538.                                       const VPoint& itsSize,
  539.                                       SizeDeterminer itsHSizeDet,
  540.                                       SizeDeterminer itsVSizeDet,
  541.                                       short numOfRows,
  542.                                       short numOfCols,
  543.                                       short rowHeight,
  544.                                       short colWidth,
  545.                                       Boolean adornRows,
  546.                                       Boolean adornCols,
  547.                                       short rowInset,
  548.                                       short colInset,
  549.                                       Boolean singleSelection,
  550.                                       const TextStyle& itsTextStyle);
  551.         // Initialize the TextGridView. If numOfRows or numOfCols is non-zero then the
  552.         // gridview is initialized to the specified size. The row and height of the cells
  553.         // is determine by the font size, style etc. The default size may be changed with
  554.         // calls to the the SetRowHeight and SetColWidth methods. If either adorn is
  555.         // kDontAdorn, then that adorn will not be called. The "Insets" allow space
  556.         // between cells and may be used to draw row and column adornments.
  557.  
  558.     //------------------------------------------------------------------------------------
  559.     // Standard signature support.
  560.     //------------------------------------------------------------------------------------
  561.  
  562.     virtual IDType GetStandardSignature();    // override 
  563.         // Returns this class's standard signature.
  564.  
  565.     //------------------------------------------------------------------------------------
  566.     // Stream I/O protocol support.
  567.     //------------------------------------------------------------------------------------
  568.  
  569.     virtual void ReadFields(TStream* aStream);    // override 
  570.     
  571.     virtual void WriteFields(TStream* aStream);    // override 
  572.  
  573.     //------------------------------------------------------------------------------------
  574.     // Methods To OVERRIDE
  575.     //------------------------------------------------------------------------------------
  576.  
  577.     virtual void GetText(GridCell aCell, CStr255& aString);
  578.         // This routine gets the text to be draw in a given cell. IT MUST BE OVERRIDDEN!
  579.  
  580. #if qDrag
  581.     //------------------------------------------------------------------------------------
  582.     // Drag and Drop Methods
  583.     //------------------------------------------------------------------------------------
  584.     
  585.     virtual void DoAddDragContent();
  586.     
  587.     virtual void DoFulfillPromise(TDragItem* promisedItem);
  588.     
  589. #endif // qDrag
  590.     //------------------------------------------------------------------------------------
  591.     // General Methods
  592.     //------------------------------------------------------------------------------------
  593.  
  594.     virtual void DrawCell(GridCell aCell, const VRect& aRect);
  595.         // Calls GetText and then draws the text
  596.  
  597.     virtual Boolean Focus();
  598.         // Calls Inherited::Focus and calls SetUpFont
  599.  
  600.     virtual void SetUpFont();
  601.         // Sets up the font for this view.
  602.  
  603.     virtual void SetPen();
  604.         // Sets the font characteristics of the current port. Called at the beginning of
  605.         // the Draw method.
  606.  
  607.     //----------------------------------------------------------------------------------------
  608.     // data members
  609.     //----------------------------------------------------------------------------------------
  610. public:
  611.     TextStyle fTextStyle;                        // The text style (color, size, etc. )
  612.  
  613.     short fTextStyleRsrcID;                        // Rsrc ID of 'TxSt' resource which has
  614.                                                 // TextStyle information.
  615.  
  616.     short fJustification;                        // Justification of text cells
  617.  
  618.     short fLineHeight;                            // height of each item including leading
  619.  
  620.     short fLineAscent;                            // pos. of baseline relative to top of
  621.                                                 // line
  622.  
  623.     Boolean fPreferOutline;                        // prefer outline fonts?
  624.  
  625. };
  626.  
  627.  
  628. //----------------------------------------------------------------------------------------
  629. // TTextListView: This subclass of TTextGridView handles lists in a manner similar to the
  630. // List Manager in the toolbox. These lists typically consist of single columns and the
  631. // case of this subclass handle the placeme { Initialization and Free Methods
  632. //----------------------------------------------------------------------------------------
  633.  
  634. class TTextListView : public TTextGridView
  635. {
  636.     MA_DECLARE_CLASS;
  637.     
  638. public:
  639.     TTextListView();
  640.         // Constructor
  641.     virtual ~TTextListView();
  642.         // Destructor
  643.         
  644.     void ITextListView(TDocument* itsDocument,
  645.                                       TView* itsSuperView,
  646.                                       const VPoint& itsLocation,
  647.                                       const VPoint& itsSize,
  648.                                       SizeDeterminer itsHSizeDet,
  649.                                       SizeDeterminer itsVSizeDet,
  650.                                       short numOfItems,
  651.                                       short rowHeight,
  652.                                       short colWidth,
  653.                                       Boolean adornRows,
  654.                                       Boolean adornCols,
  655.                                       short rowInset,
  656.                                       short colInset,
  657.                                       Boolean singleSelection,
  658.                                       const TextStyle& itsTextStyle);
  659.         // Initialize the TextListView. If numOfItems is non-zero then the listview is
  660.         // initialized to the specified size. The width and height of the items are
  661.         // determined by the font size, style etc. The default size may be changed with
  662.         // calls to the the SetItemHeight and SetItemWidth methods. The "Insets" allow
  663.         // space between items.
  664.  
  665.     //------------------------------------------------------------------------------------
  666.     // Standard signature support.
  667.     //------------------------------------------------------------------------------------
  668.  
  669.     virtual IDType GetStandardSignature();    // override 
  670.         // Returns this class's standard signature.
  671.  
  672.     //------------------------------------------------------------------------------------
  673.     // Methods To OVERRIDE
  674.     //------------------------------------------------------------------------------------
  675.  
  676.     virtual void GetItemText(short anItem, CStr255& aString);
  677.         // Get the text to be drawn for a given item. THIS METHOD MUST BE OVERRIDDEN !!
  678.  
  679.     virtual short GetItemIndexOrdered(short nthItem);
  680.         // Override this method if you are using the key selection behavior and the items
  681.         // returned by GetItemText are not in alpha order. Return the position in the text
  682.         // list of the 'nthItem' in alpha order.
  683.         
  684.     virtual Boolean CanSelectItem(short anItem);
  685.         // Determine if the item is selectable
  686.  
  687.  
  688.     //------------------------------------------------------------------------------------
  689.     // General Methods
  690.     //------------------------------------------------------------------------------------
  691.  
  692.     virtual Boolean CanSelectCell(GridCell aCell);
  693.         // This method checks to see if a cell can be selected. This method simply calls
  694.         // CanSelectItem
  695.  
  696.     virtual void DelItemAt(short anItem, short numOfItems);
  697.         // Delete the specified items.This causes a redraw of only the necessary cells.
  698.  
  699.     virtual void DelItemFirst(short numOfItems);
  700.         // Delete the specified items.This causes a redraw of only the necessary cells.
  701.  
  702.     virtual void DelItemLast(short numOfItems);
  703.         // Delete the specified items.This causes a redraw of only the necessary cells.
  704.  
  705.     virtual void DoKeySelection(const CStr255& selectionString);
  706.         // Selection the proper element in this list view based on the partial CString
  707.         // 'selectionString'. This will be called by the key selection behavior if one is
  708.         // added to this view.
  709.  
  710.     virtual short GetItemHeight(short anItem);
  711.         // Return the height of the specified item.
  712.  
  713.     virtual short GetItemWidth();
  714.         // Return the width of the view.
  715.  
  716.     virtual void GetText(GridCell aCell, CStr255& aString);
  717.         // Calls GetItemText with an item number.
  718.  
  719.     virtual void InsItemBefore(short anItem, short numOfItems);
  720.         // Insert numOfItems before anItem in the list.
  721.  
  722.     virtual void InsItemFirst(short numOfItems);
  723.         // Insert numOfItems at the beginning of the list.
  724.  
  725.     virtual void InsItemLast(short numOfItems);
  726.         // Insert numOfItems at the end of the list.
  727.  
  728.     virtual Boolean IsItemSelected(short anItem);
  729.         // Check if the specified item is currently selected.
  730.  
  731.     virtual void SetFrame(const VRect& newFrame, Boolean invalidate);
  732.         // Resize the view.
  733.  
  734.     virtual void SelectCell(GridCell theCell,
  735.                                    Boolean extendSelection,
  736.                                    Boolean highlight,
  737.                                    Boolean select);
  738.         // Calls SelectItem with the appropriate item number
  739.  
  740.     virtual void SelectItem(short anItem,
  741.                                    Boolean extendSelection,
  742.                                    Boolean highlight,
  743.                                    Boolean select);
  744.         // Select the given item. If extend is true then the item is added to the current
  745.         // selection. Otherwise the current selection is deselected. If highlight is true
  746.         // then the selected item is highlighted.
  747.  
  748.     virtual void SetItemHeight(short anItem,
  749.                                       short numOfItems,
  750.                                       short aHeight);
  751.         // Set the height of an item to be different from the default.This changes the
  752.         // height of only the specified items.
  753.  
  754.     virtual void SetItemWidth(short aWidth);
  755.         // Set the width of the view to aWidth. (This changes the width of all the items.
  756.  
  757.     virtual short FirstSelectedItem();
  758.         // Returns the first item selected.
  759.  
  760.     virtual short LastSelectedItem();
  761.         // Returns the last item selected.
  762.  
  763.     virtual void InvalidateItem(short anItem);
  764.         // Invalidates the given item, causing it to be redrawn
  765.  
  766. };
  767.  
  768.  
  769. //----------------------------------------------------------------------------------------
  770. // TCellSelectCommand
  771. //----------------------------------------------------------------------------------------
  772.  
  773. class TCellSelectCommand : public TTracker
  774. {
  775.     MA_DECLARE_CLASS;
  776.     
  777. public:
  778.  
  779.     TCellSelectCommand();
  780.         // Constructor
  781.         
  782.     void ICellSelectCommand(TGridView* itsView,
  783.                                            const VPoint& itsMouse,
  784.                                            Boolean theShiftKey,
  785.                                            Boolean theCommandKey);
  786.         // Initialize the command object.
  787.  
  788.     virtual ~TCellSelectCommand();
  789.         // If the region fPreviousSelection and fDifference are not NULL then dispose of them
  790.         // before calling Inherited::Free.
  791.  
  792.     virtual void TrackFeedback(TrackPhase aTrackPhase,
  793.                                         const VPoint& anchorPoint,
  794.                                         const VPoint& previousPoint,
  795.                                         const VPoint& nextPoint,
  796.                                         Boolean mouseDidMove,
  797.                                         Boolean turnItOn);
  798.         // Override this method to give feedback while the mouse button is down. The
  799.         // default does nothing.
  800.  
  801.     virtual TTracker* TrackMouse(TrackPhase aTrackPhase,
  802.                                         VPoint& anchorPoint,
  803.                                         VPoint& previousPoint,
  804.                                         VPoint& nextPoint,
  805.                                         Boolean mouseDidMove);
  806.         // Track the mouse when the button is down.
  807.  
  808.     virtual void DoIt();
  809.         // The method that will do the actual task to be performed by the command.MUST BE
  810.         // OVERRIDDEN.
  811.  
  812.     virtual void ComputeAnchorCell(GridCell& clickedCell);
  813.         // Computes the cell that the mouse is first clicked in when making a selection.
  814.  
  815.     virtual void ComputeNewSelection(GridCell& clickedCell);
  816.         // Calculate what the new selection should be.
  817.  
  818.     virtual void HighlightNewSelection();
  819.         // Highlight the new selection.
  820.  
  821.     //----------------------------------------------------------------------------------------
  822.     // data members
  823.     //----------------------------------------------------------------------------------------
  824. public:
  825.     TGridView* fGridView;                        // The associated GridView
  826.     RgnHandle fThisSelection;
  827.     RgnHandle fPreviousSelection;
  828.     RgnHandle fDifference;
  829.     GridCell fAnchorCell;
  830.     GridCell fPreviousCell;
  831.     Boolean fShiftKey;                            // Shift Key down?
  832.     Boolean fCommandKey;                            // Command Key down?
  833.     Boolean fDeselecting;
  834. };
  835.  
  836.  
  837. //----------------------------------------------------------------------------------------
  838. // TRCSelectCommand: An abstract superclass for row and column selection.
  839. //----------------------------------------------------------------------------------------
  840.  
  841. class TRCSelectCommand : public TCellSelectCommand
  842. {
  843.     MA_DECLARE_CLASS;
  844.     
  845. public:
  846.     TRCSelectCommand();
  847.         // Empty constructor to satisfy compiler.
  848.     virtual ~TRCSelectCommand();
  849.         // Destructor
  850.         
  851.     void IRCSelectCommand(TGridView* itsView,
  852.                                            const VPoint& itsMouse,
  853.                                            Boolean theShiftKey,
  854.                                            Boolean theCommandKey);
  855.         // Initialization method for TRCSelectCommand.
  856.  
  857.     virtual void ComputeNewSelection(GridCell& clickedCell);
  858.         // Computes the new selection.
  859.  
  860.     virtual TTracker* TrackMouse(TrackPhase aTrackPhase,
  861.                                         VPoint& anchorPoint,
  862.                                         VPoint& previousPoint,
  863.                                         VPoint& nextPoint,
  864.                                         Boolean mouseDidMove);
  865.         // Track the mouse during selection.
  866.  
  867. };
  868.  
  869.  
  870. //----------------------------------------------------------------------------------------
  871. // TRowSelectCommand: A subclass that performs selections on rows
  872. //----------------------------------------------------------------------------------------
  873.  
  874. class TRowSelectCommand : public TRCSelectCommand
  875. {
  876.     MA_DECLARE_CLASS;
  877.     
  878. public:
  879.     TRowSelectCommand();
  880.         // Empty constructor to satisfy compiler.
  881.     virtual ~TRowSelectCommand();
  882.         // Destructor
  883.         
  884.     void IRowSelectCommand(TGridView* itsView,
  885.                                           const VPoint& itsMouse,
  886.                                           Boolean theShiftKey,
  887.                                           Boolean theCommandKey);
  888.         // Initialization of command.
  889.  
  890.     virtual void ComputeAnchorCell(GridCell& clickedCell);
  891.         // Override of method to perform computations specific to row selection.
  892.  
  893.     virtual void ComputeNewSelection(GridCell& clickedCell);
  894.         // Override of method to perfom computation of new selection specific to row
  895.         // selection.
  896.  
  897. };
  898.  
  899.  
  900. //----------------------------------------------------------------------------------------
  901. // TColumnSelectCommand: A subclass that handles the selection of columns in a GridView.
  902. //----------------------------------------------------------------------------------------
  903.  
  904. class TColumnSelectCommand : public TRCSelectCommand
  905. {
  906.     MA_DECLARE_CLASS;
  907.     
  908. public:
  909.     TColumnSelectCommand();
  910.         // Empty constructor to satisfy compiler.
  911.     virtual ~TColumnSelectCommand();
  912.         // Destructor
  913.         
  914.     void IColumnSelectCommand(TGridView* itsView,
  915.                                              const VPoint& itsMouse,
  916.                                              Boolean theShiftKey,
  917.                                              Boolean theCommandKey);
  918.         // Initialization method.
  919.  
  920.     virtual void ComputeAnchorCell(GridCell& clickedCell);
  921.         // Override of method to perform computations specific to column selection.
  922.  
  923.     virtual void ComputeNewSelection(GridCell& clickedCell);
  924.         // Override of method to perform computation of new selection specific to column
  925.         // selection.
  926.  
  927. };
  928.  
  929.  
  930. //----------------------------------------------------------------------------------------
  931. // CRowIterator: an iterator class designed to replace the EachRowDo method of
  932. // TGridView.  APW 6-13
  933. //----------------------------------------------------------------------------------------
  934.  
  935. class CRowIterator : public CIterator
  936. {
  937. public:
  938.     static const short kNullRow; 
  939.  
  940.     CRowIterator(const TGridView*    itsGridView,
  941.                             short        startRow,
  942.                             short        stopRow,
  943.                             Boolean        itsForward);
  944.                             
  945.     CRowIterator(const TGridView* itsGridView, Boolean itsForward);
  946.     CRowIterator(const TGridView* itsGridView);
  947.     short FirstRow();
  948.     short NextRow();
  949.     Boolean More();                         //override!!!
  950.     void Reset();                             //override!!!
  951.     
  952. protected:
  953.     void Advance();                            //override!!!
  954.  
  955. private:
  956.     void IRowIterator(const TGridView*    itsGridView,    //called exclusively by the
  957.                                 short        startRow,        //constructors of this class.
  958.                                 short        stopRow,
  959.                                 Boolean        itsForward); 
  960.  
  961.     //----------------------------------------------------------------------------------------
  962.     // data members
  963.     //----------------------------------------------------------------------------------------
  964. protected:
  965.     short     fCurrentRow;
  966.     short    fFirstRow;
  967.     short    fLastRow;
  968.     Boolean    fIterateForward;
  969. };
  970.  
  971. //----------------------------------------------------------------------------------------
  972. // CColumnIterator: an iterator class designed to replace the EachColumnDo
  973. // method of TGridView.  APW 6-13
  974. //----------------------------------------------------------------------------------------
  975.  
  976. class CColumnIterator : public CIterator
  977. {
  978. public:
  979.     static const short kNullColumn; 
  980.  
  981.     CColumnIterator(const TGridView*    itsGridView,
  982.                             short        startColumn,
  983.                             short        stopColumn,
  984.                             Boolean        itsForward);
  985.                             
  986.     CColumnIterator(const TGridView* itsGridView, Boolean itsForward);
  987.     CColumnIterator(const TGridView* itsGridView);
  988.     short FirstColumn();
  989.     short NextColumn();
  990.     Boolean More();                         //override!!!
  991.     void Reset();                             //override!!!
  992.     
  993. protected:
  994.     void Advance();                            //override!!!
  995.  
  996. private:
  997.     void IColumnIterator(const TGridView*    itsGridView,    //to be called exclusively
  998.                                     short        startColumn,    //by the constructors of
  999.                                     short        stopColumn,        //this class.
  1000.                                     Boolean        itsForward); 
  1001.     //----------------------------------------------------------------------------------------
  1002.     // data members
  1003.     //----------------------------------------------------------------------------------------
  1004. protected:
  1005.     short     fCurrentColumn;
  1006.     short    fFirstColumn;
  1007.     short    fLastColumn;
  1008.     Boolean    fIterateForward;
  1009. };
  1010.  
  1011. //----------------------------------------------------------------------------------------
  1012. // CCellIterator: an iterator class designed to replace the EachCellDo method
  1013. // of TGridView.  APW 6-13
  1014. //----------------------------------------------------------------------------------------
  1015.  
  1016. class CCellIterator : public CIterator
  1017. {
  1018. public:
  1019.     static const GridCell kNullCell; 
  1020.     static const Boolean kIterateRowMajor;
  1021.     
  1022.     CCellIterator(const TGridView*    itsGridView,
  1023.                             GridCell    startCell,
  1024.                             GridCell    stopCell,
  1025.                             Boolean        itsRowForward,
  1026.                             Boolean        itsColumnForward,
  1027.                             Boolean        itsRowMajor);
  1028.                             
  1029.     CCellIterator(const TGridView*    itsGridView,
  1030.                             Boolean        itsRowForward,
  1031.                             Boolean        itsColumnForward,
  1032.                             Boolean        itsRowMajor);
  1033.  
  1034.     CCellIterator(const TGridView* itsGridView);
  1035.  
  1036.     GridCell FirstCell();
  1037.  
  1038.     GridCell NextCell();
  1039.  
  1040.     Boolean More();                         //override!!!
  1041.  
  1042.     void Reset();                             //override!!!
  1043.     
  1044. protected:
  1045.     void Advance();                            //override!!!
  1046.  
  1047.     //----------------------------------------------------------------------------------------
  1048.     // data members
  1049.     //----------------------------------------------------------------------------------------
  1050. protected:
  1051.     CRowIterator    fRowIterator;
  1052.     CColumnIterator    fColumnIterator;
  1053.     GridCell     fCurrentCell;
  1054.     Boolean        fIterateRowMajor;
  1055. };
  1056.  
  1057.  
  1058. //----------------------------------------------------------------------------------------
  1059. // CCellInRegionIterator: an iterator class designed to replace the EachInRegion method
  1060. // of TGridView.  APW 7-15
  1061. //----------------------------------------------------------------------------------------
  1062.  
  1063. class CCellInRegionIterator : public CCellIterator
  1064. {
  1065. public:
  1066.     CCellInRegionIterator(const TGridView*    itsGridView,
  1067.                             RgnHandle    aRegion,
  1068.                             Boolean        itsRowForward,
  1069.                             Boolean        itsColumnForward,
  1070.                             Boolean        itsRowMajor);
  1071.  
  1072.     CCellInRegionIterator(const TGridView*    itsGridView,
  1073.                             RgnHandle    aRegion);
  1074.  
  1075.     void Reset();                             //override!!!
  1076.     
  1077. protected:
  1078.     void Advance();                            //override!!!
  1079.     
  1080.     Boolean CellIsInRegion();
  1081.  
  1082.     //----------------------------------------------------------------------------------------
  1083.     // data members
  1084.     //----------------------------------------------------------------------------------------
  1085. protected:
  1086.     RgnHandle    fRegion;
  1087.  
  1088.     Boolean        fIsRectangularRegion;
  1089. };
  1090.  
  1091. //----------------------------------------------------------------------------------------
  1092. // CSelectedCellIterator: an iterator class designed to replace the EachSelectedCellDo method
  1093. // of TGridView.  APW 7-15
  1094. //----------------------------------------------------------------------------------------
  1095.  
  1096. class CSelectedCellIterator : public CCellInRegionIterator
  1097. {
  1098. public:
  1099.     CSelectedCellIterator(const TGridView*    itsGridView,
  1100.                             Boolean        itsRowForward,
  1101.                             Boolean        itsColumnForward,
  1102.                             Boolean        itsRowMajor);
  1103.  
  1104.     CSelectedCellIterator(const TGridView*    itsGridView);
  1105.  
  1106.     void Reset();                             //override!!!
  1107.     
  1108. };
  1109.  
  1110.  
  1111.  
  1112. //----------------------------------------------------------------------------------------
  1113. // Global variable declarations. These are intended to be private, but are in the
  1114. // interface so that you can use these regions if you override the methods that use them.
  1115. //----------------------------------------------------------------------------------------
  1116.  
  1117. extern RgnHandle pPixelsToHighlight;            // Used by HighlightCells
  1118.  
  1119. extern RgnHandle pPreviousSelection;            // Used by SetSelection
  1120.  
  1121. extern RgnHandle pDifference;                    // Used by SetSelection
  1122.  
  1123. extern RgnHandle pVisibleCells;                    // Used by CellsToPixels
  1124.  
  1125. extern RgnHandle pInvalidateRgn;                // Used by InvalidateSelection
  1126.  
  1127.  
  1128. //----------------------------------------------------------------------------------------
  1129. // Global functions declarations.
  1130. //----------------------------------------------------------------------------------------
  1131.  
  1132. extern void InitUGridView();                
  1133.     // Creates all the regions used by the GridView class and then sets the global flag
  1134.     // 'gUGridViewInitialized'.
  1135.  
  1136.  
  1137. #endif
  1138.  
  1139.  
  1140.